<template>
    <el-form :model="queryParams" :ref="viewData.id" :inline="true" v-show="queryParams.showSearch" label-width="68px">
      <component
          v-for="p in viewData.properties"
          v-bind:is="'rva-search-' + p.type"
          v-model="queryParams[p.id]"
          :prop="p" :key="p.id">
      </component>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
</template>

<script>
import RvaSearchTextfield from "@/components/rva/search/textfield";
import RvaSearchSelect from "@/components/rva/search/select";
import RvaSearchSelector from "@/components/rva/search/selector";
import RvaSearchRadio from "@/components/rva/search/radio";
import RvaSearchCheckbox from "@/components/rva/search/checkbox";

import {getRvaViewData} from "@/api/rva/crud";
import RvaSearchConfig from "@/components/rva/search/config";
import Vue from "vue";

Vue.component('rva-search-config', RvaSearchConfig)

export default {
  name: "RvaSearchView",
  props: ['viewId', 'queryParams', 'requestParams'],
  components: {
    "rva-search-textfield": RvaSearchTextfield,
    "rva-search-select": RvaSearchSelect,
    "rva-search-selector": RvaSearchSelector,
    "rva-search-radio": RvaSearchRadio,
    "rva-search-checkbox": RvaSearchCheckbox,
  },
  data() {
    return {
      viewData: {}
    };
  },
  created() {
    // 设置this.viewData
    getRvaViewData(this.viewId, this.requestParams, this)
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.trigger ++; // 以此使queryParams变化，从而触发loadList
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
